﻿using System;
using System.Collections;
using System.Xml.Serialization;

namespace PVTLibrary
{
    [Serializable]
    public class ConstantProperties : ICloneable
    {
        public string Name = "";
        public string CAS_Number = "";
        public string Formula = "";
        public string SMILES = "";
        public string InChI = "";
        public string ChemicalStructure = "";
        public double Molar_Weight;
        public double Critical_Temperature;
        public double Critical_Pressure;
        public double Critical_Volume;
        public double Critical_Compressibility;
        public double Acentric_Factor;
        public double Z_Rackett;
        public double PR_Volume_Translation_Coefficient;
        public double SRK_Volume_Translation_Coefficient;
        public double Chao_Seader_Acentricity;
        public double Chao_Seader_Solubility_Parameter;
        public double Chao_Seader_Liquid_Molar_Volume;
        public double IG_Entropy_of_Formation_25C;
        public double IG_Enthalpy_of_Formation_25C;
        public double IG_Gibbs_Energy_of_Formation_25C;
        public double Dipole_Moment;
        public double Vapor_Pressure_Constant_A;
        public double Vapor_Pressure_Constant_B;
        public double Vapor_Pressure_Constant_C;
        public double Vapor_Pressure_Constant_D;
        public double Vapor_Pressure_Constant_E;
        public double Vapor_Pressure_TMIN;
        public double Vapor_Pressure_TMAX;
        public double Ideal_Gas_Heat_Capacity_Const_A;
        public double Ideal_Gas_Heat_Capacity_Const_B;
        public double Ideal_Gas_Heat_Capacity_Const_C;
        public double Ideal_Gas_Heat_Capacity_Const_D;
        public double Ideal_Gas_Heat_Capacity_Const_E;
        public double Liquid_Viscosity_Const_A;
        public double Liquid_Viscosity_Const_B;
        public double Liquid_Viscosity_Const_C;
        public double Liquid_Viscosity_Const_D;
        public double Liquid_Viscosity_Const_E;
        public double Liquid_Density_Const_A;
        public double Liquid_Density_Const_B;
        public double Liquid_Density_Const_C;
        public double Liquid_Density_Const_D;
        public double Liquid_Density_Const_E;
        public double Liquid_Density_Tmin;
        public double Liquid_Density_Tmax;
        public double Liquid_Heat_Capacity_Const_A;
        public double Liquid_Heat_Capacity_Const_B;
        public double Liquid_Heat_Capacity_Const_C;
        public double Liquid_Heat_Capacity_Const_D;
        public double Liquid_Heat_Capacity_Const_E;
        public double Liquid_Heat_Capacity_Tmin;
        public double Liquid_Heat_Capacity_Tmax;
        public double Liquid_Thermal_Conductivity_Const_A;
        public double Liquid_Thermal_Conductivity_Const_B;
        public double Liquid_Thermal_Conductivity_Const_C;
        public double Liquid_Thermal_Conductivity_Const_D;
        public double Liquid_Thermal_Conductivity_Const_E;
        public double Liquid_Thermal_Conductivity_Tmin;
        public double Liquid_Thermal_Conductivity_Tmax;
        public double Solid_Density_Const_A;
        public double Solid_Density_Const_B;
        public double Solid_Density_Const_C;
        public double Solid_Density_Const_D;
        public double Solid_Density_Const_E;
        public double Solid_Density_Tmin;
        public double Solid_Density_Tmax;
        public double Solid_Heat_Capacity_Const_A;
        public double Solid_Heat_Capacity_Const_B;
        public double Solid_Heat_Capacity_Const_C;
        public double Solid_Heat_Capacity_Const_D;
        public double Solid_Heat_Capacity_Const_E;
        public double Solid_Heat_Capacity_Tmin;
        public double Solid_Heat_Capacity_Tmax;
        public double Normal_Boiling_Point;
        public int ID;
        public int IsPF = 0;
        public int IsHYPO = 0;
        public double HVap_A;
        public double HVap_B;
        public double HVap_C;
        public double HVap_D;
        public double HVap_TMIN;
        public double HVap_TMAX;
        public double UNIQUAC_R;
        public double UNIQUAC_Q;

        public UNIFACGroupCollection UNIFACGroups;
        public UNIFACGroupCollection MODFACGroups;
        public ElementCollection Elements;

        public string VaporPressureEquation = "";
        public string IdealgasCpEquation = "";
        public string LiquidViscosityEquation = "";
        public string VaporizationEnthalpyEquation = "";
        public string LiquidDensityEquation = "";
        public string LiquidHeatCapacityEquation = "";
        public string LiquidThermalConductivityEquation = "";
        public string SolidDensityEquation = "";
        public string SolidHeatCapacityEquation = "";

        public double PC_SAFT_sigma = 0.0;
        public double PC_SAFT_epsilon_k = 0.0;
        public double PC_SAFT_m = 0.0;

        public Nullable<double> PF_MM = null;
        public Nullable<double> NBP = null;
        public Nullable<double> PF_vA = null;
        public Nullable<double> PF_vB = null;
        public Nullable<double> PF_Watson_K = null;
        public Nullable<double> PF_SG = null;
        public Nullable<double> PF_v1 = null;
        public Nullable<double> PF_Tv1 = null;
        public Nullable<double> PF_v2 = null;
        public Nullable<double> PF_Tv2 = null;

        //Databases: 'DWSIM', 'CheResources', 'ChemSep' OR 'User'
        //User databases are XML-serialized versions of this base class, and they may include hypos and pseudos.
        public string OriginalDB = "DWSIM";
        public string CurrentDB = "DWSIM";

        //'COSMO-SAC's database equivalent name
        public string COSMODBName = "";

        //'Electrolyte-related properties
        public bool IsIon = false;
        public bool IsSalt = false;
        public bool IsHydratedSalt = false;
        public double HydrationNumber = 0.0;
        public int Charge = 0;
        public string PositiveIon = "";
        public string NegativeIon = "";
        public int PositiveIonStoichCoeff = 0;
        public int NegativeIonStoichCoeff = 0;
        public int StoichSum = 0;
        public double Electrolyte_DelGF = 0.0;
        public double Electrolyte_DelHF = 0.0;
        public double Electrolyte_Cp0 = 0.0;
        public double TemperatureOfFusion = 0.0;
        public double EnthalpyOfFusionAtTf = 0.0;
        public double SolidTs = 0.0;
        public double SolidDensityAtTs = 0.0;
        public double StandardStateMolarVolume = 0.0;
        public double MolarVolume_v2i = 0.0;
        public double MolarVolume_v3i = 0.0;
        public double MolarVolume_k1i = 0.0;
        public double MolarVolume_k2i = 0.0;
        public double MolarVolume_k3i = 0.0;
        public double Ion_CpAq_a = 0.0;
        public double Ion_CpAq_b = 0.0;
        public double Ion_CpAq_c = 0.0;

        //'the following properties are no longer used but kept for compatibility reasons
        [XmlIgnore]
        public double UNIFAC_Ri;
        [XmlIgnore]
        public double UNIFAC_Qi;

        [XmlIgnore]
        public int UNIFAC_01_CH4;
        [XmlIgnore]
        public int UNIFAC_02_CH3;
        [XmlIgnore]
        public int UNIFAC_03_CH2;
        [XmlIgnore]
        public int UNIFAC_04_CH;
        [XmlIgnore]
        public int UNIFAC_05_H2O;
        [XmlIgnore]
        public int UNIFAC_06_H2S;
        [XmlIgnore]
        public int UNIFAC_07_CO2;
        [XmlIgnore]
        public int UNIFAC_08_N2;
        [XmlIgnore]
        public int UNIFAC_09_O2;
        [XmlIgnore]
        public int UNIFAC_10_OH;
        [XmlIgnore]
        public int UNIFAC_11_ACH;
        [XmlIgnore]
        public int UNIFAC_12_ACCH2;
        [XmlIgnore]
        public int UNIFAC_13_ACCH3;
        [XmlIgnore]
        public int UNIFAC_14_ACOH;
        [XmlIgnore]
        public int UNIFAC_15_CH3CO;
        [XmlIgnore]
        public int UNIFAC_16_CH2CO;
        [XmlIgnore]
        public int Element_C = 0;
        [XmlIgnore]
        public int Element_H = 0;
        [XmlIgnore]
        public int Element_O = 0;
        [XmlIgnore]
        public int Element_N = 0;
        [XmlIgnore]
        public int Element_S = 0;

        public ConstantProperties()
        {
            UNIFACGroups = new UNIFACGroupCollection();
            MODFACGroups = new UNIFACGroupCollection();
        }


        public object Clone()
        {
            return null;
            //modif adel
            //Return ObjectCopy(Me)
        }

        /*
        Function ObjectCopy(ByVal obj As ConstantProperties) As ConstantProperties

            Dim objMemStream As New MemoryStream(50000)
            Dim objBinaryFormatter As New BinaryFormatter(null, New StreamingContext(StreamingContextStates.Clone))

            objBinaryFormatter.Serialize(objMemStream, obj)

            objMemStream.Seek(0, SeekOrigin.Begin)

            ObjectCopy = objBinaryFormatter.Deserialize(objMemStream)

            objMemStream.Close()

        End Function*/
    }

    [Serializable]
    public class ConstantPropertiesCollection
    {
        public ConstantProperties Collection = new ConstantProperties();
    }


    [Serializable]
    public class UNIFACGroupCollection
    {
        public SortedList Collection;
        public UNIFACGroupCollection()
        {
            Collection = new System.Collections.SortedList();
        }
    }

    [Serializable]
    public class ElementCollection
    {
        public SortedList Collection;
        public ElementCollection()
        {
            Collection = new System.Collections.SortedList();
        }
    }
}